package com;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.util.Scanner;

public class _04_UDPClient {

	public static void main(String[] args) throws IOException {
		// 1
		String string = null;
		Scanner sc = new Scanner(System.in);
		string = sc.nextLine();
		while (!string.trim().equals(" ")) {
			// 把数据拆分成字节数组
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			DataOutputStream dos = new DataOutputStream(baos);
			dos.writeUTF(string);

			// 把数据写入字节数组中
//			byte[] buf = baos.toByteArray();
			byte[] buf = string.getBytes();

			// 数据传输

			// 数据包
			DatagramPacket dp = new DatagramPacket(buf, buf.length, new InetSocketAddress("127.0.0.1", 10000));
			// 开启端口,把包发送出去
			DatagramSocket ds = new DatagramSocket();
			ds.send(dp);
			ds.close();

			// 再次接收控制台输入
			string = sc.nextLine();
		}
		System.out.println("退出");
	}

}
